package com.zzyl.nursing.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 * 
 * @author zhaoyiyang
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;
    /*
    * 查询当天取消预约数量
    * */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询当天取消预约数量")
    public AjaxResult findCancelledCount()
    {
        return success(reservationService.findCancelledCount());
    }

    /**
     * 获取预约信息详细信息
     */
    @GetMapping(value = "/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public AjaxResult countByTime(
            @ApiParam(value = "预约信息ID", required = true)
            Long time
    )
    {
        return reservationService.countByTime(time);
    }

    /**
     * 新增预约信息
     */
    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult add(@ApiParam(value = "预约信息实体", required = true) @RequestBody Reservation reservation)
    {
        return toAjax(reservationService.insertReservation(reservation));
    }

    /**
     * 查询预约信息列表
     */
    @GetMapping("/page")
    @ApiOperation(value = "获取预约信息列表")
    public TableDataInfo<List<Reservation>> list(Reservation reservation)
    {
        startPage();
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return getDataTable(list);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation(value = "取消预约")
    public AjaxResult cancelReservation(@PathVariable Long id) {
        return reservationService.cancelReservation(id);
    }




}
